part of '../service.dart';

class _AppStoreApiAccessTokenClaimDto extends Equatable {
  const _AppStoreApiAccessTokenClaimDto._internal({
    required this.issuerId,
    required this.issueTimeS,
    required this.expirationTimeS,
    required this.audience,
    required this.bundleId,
  });

  final String issuerId;
  final int issueTimeS;
  final int expirationTimeS;
  final String audience;
  final String bundleId;

  @override
  List<Object?> get props {
    return [
      issuerId,
      issueTimeS,
      expirationTimeS,
      audience,
      bundleId,
    ];
  }

  factory _AppStoreApiAccessTokenClaimDto.fromEntity(AppStoreApiAccessTokenClaim accessTokenClaim) {
    return _AppStoreApiAccessTokenClaimDto._internal(
      issuerId: accessTokenClaim.issuerId,
      issueTimeS: accessTokenClaim.issueTime.millisecondsSinceEpoch ~/ 1000,
      expirationTimeS: accessTokenClaim.expirationTime.millisecondsSinceEpoch ~/ 1000,
      audience: accessTokenClaim.audience,
      bundleId: accessTokenClaim.bundleId,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'iss': issuerId,
      'iat': issueTimeS,
      'exp': expirationTimeS,
      'aud': audience,
      'bid': bundleId,
    };
  }
}
